/**
 * Copyright 2013 DJSearch Co.,Ltd. All rights reserved.
 * DTM PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.djsearch.controller;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author dingzhongchang
 * @version 1.0.0
 */
public class JSONResp extends JSONObject implements IResponse {


	/**
	 * 默认构造方法
	 */
	public JSONResp() {
		super();
	}

	/**
	 * 构造返回结果
	 * 
	 * @param json
	 *            String
	 * @throws JSONException
	 */
	public JSONResp(String json) throws JSONException {
		super(json);
		/**
		 * if (buffData.startsWith("{")) { JSONObject object = new
		 * JSONObject(buffData); jsonData.parse(object); } else if
		 * (buffData.startsWith("[")) { JSONArray object = new
		 * JSONArray(buff.toString()); jsonData.parse(object); }
		 */
	}

	@Override
	public int result() {
		try {
			if (get("result") != null) {
				return Integer.valueOf(get("result").toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			return IResponse.Fail;
		}
		return IResponse.Fail;
	}

	@Override
	public String getValue(String key) {

		try {
			if (get(key) != null) {
				return get(key).toString();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
		return "";
	}


}
